GBML manual / Drawing

draw_rect_fill_anchored

draw_rect_fill, but the position is measured from a spot on the screen (ANCHOR_BOTTOM_LEFT, ANCHOR_CENTER, ...) instead of from the top-left corner, and it is fixed to the screen wherever you call it - a health-bar backing pinned to a corner stays pinned to it on any screen.

Works differently on Game Boy - A rectangle on the Game Boy is made of sprites and drawn in the 4 shades: red, blue and magenta come out dark grey, green, yellow, cyan and white light grey. It shares the 40 sprites on the screen (10 a line); a big box is cut short.

Works differently on Game Boy Color - Rectangles are made of sprites and share the 40 on the screen (10 a line): bars, frames and small boxes are exact, a big box is cut short. Colors come 3 to a free sprite palette, others become the nearest. On the screen they are behind sprites and text.

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

draw_rect_fill_anchored(anchor, x, y, w, h, color)

Arguments

NameType
anchoranchor
xreal
yreal
wreal
hreal
colorshape_color

Returns

Nothing.

Description

draw_rect_fill, with the position measured from a named spot on the screen (an anchor) instead of from the top-left corner. It is for a health-bar backing, a dialogue panel or any solid box that should stay pinned to a corner or an edge whatever the screen size. The anchored call is fixed to the screen wherever you write it (a Step event, a script, any event), not only in a Draw GUI event.

x moves right and y moves down from the anchor. After that come w, h and color, exactly as in draw_rect_fill.

(x, y) is the rectangle's top-left corner, measured from the anchor. So a bar that should start 4 pixels in from the left edge just says x = 4. To end 4 pixels short of the right edge, a bar w wide says x = -4 - w from ANCHOR_TOP_RIGHT.

Example

draw_rect_fill_anchored(ANCHOR_BOTTOM_CENTER, -112, -24, 224, 20, COLOR_BLACK);
draw_rect_fill_anchored(ANCHOR_BOTTOM_LEFT, 4, -10, 40, 6, COLOR_RED);

A black panel along the bottom of the screen, 224 wide and 20 tall, with a red health bar 40 wide and 6 tall drawn in front of its left end. The panel starts 112 pixels left of the middle (half of its 224) and 24 above the bottom edge, and it is 20 tall, so its bottom edge is -24 + 20 = -4: 4 pixels up. The bar starts 4 pixels in, and -10 + 6 is -4, so its bottom edge is 4 up too.

On the GBA

Exactly draw_rect_fill in a Draw GUI event once the anchor is added to (x, y): one or more hardware sprites per call (see draw_rect_fill: every size is drawn exactly, from as many sprites as it needs) and one affine matrix, none for a rectangle that is exactly 8 by 8 pixels, and always drawn on the front-most layer (use depth to order two screen-fixed draws). (x, y) is the rectangle's top-left corner, measured from the anchor: a bar that starts 4 pixels in from the left edge says x = 4, and a bar w wide that ends 4 pixels short of ANCHOR_TOP_RIGHT says x = -4 - w. ANCHOR_BOTTOM_LEFT is the point (0, 160) on the 240x160 screen, counting from its top-left pixel.

See also: Screen anchorsdraw_rect_filldraw_rect_anchoredANCHOR_BOTTOM_LEFT